<!--
 @Description 展室列表
 @author dumeng
 @date 2022/11/29
-->

<template>
  <section
    v-if="list.length >0"
    class="exhibition-room-list-page"
    :style="{
      'padding-top': top || 0,
      'padding-bottom': paddingBottom || 0,
      'padding-left':spacing||0,
      'padding-right':spacing||0,
    }"
  >
    <van-pull-refresh
      v-model="isLoading"
      @refresh="onRefresh"
    >
      <van-list
        v-model="loading"
        :immediate-check="false"
        :error.sync="error"
        :finished="finished"
        :finished-text="finishedText"
        loading-text="正在加载中..."
        error-text="请求失败，点击重新加载"
        @load="onLoad"
      >
        <ul v-if="option.styleDisplay ==='1' || option.styleDisplay === undefined">
          <li
            v-for="(item, i) in list"
            :key="i"
            class="list-item"
          >
            <newsListStyleThree
              v-if="item.showType == 'ZSXS_YWZTYS'"
              :item="item"
              :label-obj="labelObj"
              :option="option"
            />
            <!-- 大图 -->
            <newsListStyleSix
              v-else-if="item.showType == 'ZSXS_TWHPBTYS'"
              :item="item"
              :label-obj="labelObj"
              :option="option"
            />
            <newsListStyleOne v-else :item="item" :label-obj="labelObj" :option="option" />
          </li>
        </ul>

        <!-- isWaterfall && -->
        <div v-if="option.styleDisplay ==='2'">
          <template v-if="isWaterfall && isInitData">
            <div
              v-masonry
              transition-duration="0s"
              class="masonry-list-box"
              item-selector=".box-item"
              :fit-width="false"
              :gutter="6"
            >
              <div
                v-for="(item, index) in Gridlist"
                :key="index"
                v-masonry-tile
                class="box-item"
                @click="toDetail(item)"
              >
                <div class="item-img">
                  <label-comp v-if="labelObj !== undefined" :label-list="item.labelList" />
                  <van-image :src="setImgPath(item.courseImg, item.courseImgUrl)" :fit="option.fit">
                    <template v-slot:loading>
                      <van-loading type="spinner" size="20" />
                    </template>
                    <template v-slot:error>
                      <img src="./components/images/error-icon.png" alt>
                    </template>
                  </van-image>
                </div>
                <div class="item-bottom">
                  <div class="item-title">
                    <span>{{ item.courseName }}</span>
                  </div>
                  <div v-if="showSubTilte" class="item-desc">
                    <span>{{ item.courseIntroduce }}</span>
                  </div>
                  <!-- v-if="Likes" v-if="thumbsUp"  -->
                  <div class="item-left-txt">
                    <span>{{ item.Likes | toDecimal }}</span>
                    <img src="./components/images/likes.png" alt style="width: 15px; height: 15px;">
                  </div>
                </div>
              </div>
            </div>
          </template>
          <template v-else>
            <div
              class="list-box"
            >
              <div
                v-for="(item, index) in Gridlist"
                :key="index"
                class="box-item"
                @click="toDetail(item)"
              >
                <div class="item-img">
                  <label-comp v-if="labelObj !== undefined" :label-list="item.labelList" />
                  <van-image :src="setImgPath(item.courseImg, item.courseImgUrl)" :fit="option.fit">
                    <template v-slot:loading>
                      <van-loading type="spinner" size="20" />
                    </template>
                    <template v-slot:error>
                      <img src="./components/images/error-icon.png" alt>
                    </template>
                  </van-image>
                </div>
                <div class="item-bottom">
                  <div class="item-title etc">
                    <span>{{ item.courseName }}</span>
                  </div>
                  <div v-if="showSubTilte" class="item-desc">
                    <span>{{ item.courseIntroduce }}</span>
                  </div>
                  <!-- v-if="Likes" v-if="thumbsUp"  -->
                  <div class="item-left-txt">
                    <span>{{ item.Likes | toDecimal }}</span>
                    <img src="./components/images/likes.png" alt style="width: 15px; height: 15px;">
                  </div>
                </div>
              </div>
            </div>
          </template>
        </div>
      </van-list>
    </van-pull-refresh>

  </section>

</template>
<script>
import mixins from './../mixins'
import LabelComp from '@/components/CustomPage/apps/widget/labelComp'
import newsListStyleOne from '../exhibition_room/components/NewsListStyleOne.vue'
import newsListStyleThree from '../exhibition_room/components/NewsListStyleThree'
import newsListStyleSix from '../exhibition_room/components/NewsListStyleSix'
const defImg = ''
export default {
  name: 'ExhibitionRoom',
  inject: ['footerHeight'],
  components: {
    newsListStyleOne,
    newsListStyleThree,
    newsListStyleSix,
    LabelComp
  },
  filters: {
    toDecimal(num) {
      if (num > 10000) {
        var s = (num / 10000).toString()
        let numList = []
        let str = ''
        if (s.indexOf('.') != -1) {
          numList = s.split('.')
        } else {
          numList.push(s)
        }
        if (numList.length > 0) {
          if (numList.length == 1) {
            str = numList[0] + 'w'
          } else {
            for (let i = 0; i < numList.length; i++) {
              if (i == 0) {
                str = numList[0] + '.'
              }
              if (i == 1) {
                if (numList[i].length >= 2) {
                  const numLength = numList[i].length

                  str += numList[i].substring(0, 2)
                  if (
                    numLength > 2 &&
                      parseFloat(numList[i].substring(2, numLength)) >= 1
                  ) {
                    str += 'w+'
                  } else {
                    str += 'w'
                  }
                } else {
                  str += numList[i]
                  if (parseFloat(numList[i]) >= 1) {
                    str += 'w+'
                  } else {
                    str += 'w'
                  }
                }
              }
            }
          }
        }
        return str
      } else {
        return num
      }
    }
  },
  mixins: [mixins],
  props: {
    option: {
      type: Object,
      default() {
        return {}
      }
    },
    isInitData: {
      type: Boolean,
      default: false
    }

  },
  data() {
    return {
      view: '/API-DOCUMENT/document/file/download?id=',
      total: 0,
      isNoData: false,
      isLoadError: false,
      error: false,
      loading: false, // 是否处于加载状态
      finished: false, // 是否已加载完所有数据
      isLoading: false, // 是否处于下拉刷新状态
      finishedText: '已经到底了',
      list: [],
      /** 接口参数 start */
      page: 1,
      /** 接口参数 end */
      labelObj: undefined
    }
  },
  computed: {
    // 列表展示样式
    styleDisplay() {
      return this.option.styleDisplay
    },
    // 是否展示副标题
    showSubTilte() {
      return this.option.showSubTilte
    },
    // 是否显示点赞量
    Likes() {
      return this.option.Likes
    },
    // 是否支持点赞
    thumbsUp() {
      return this.option.thumbsUp
    },
    // 是否使用瀑布流
    isWaterfall() {
      return this.option.isWaterfall || false
    }
  },
  created() {
    if (this.isInitData) {
      this.labelObj = this.getLabelList()
      this.initData()
    } else {
      this.list = [
        {
          mainTitle: '标题',
          subTitle: '副标题',
          Likes: '1208574577',
          publishTime: '2022/3/10',
          url: 'http://beyond.3dnest.cn/play/?m=012d102a_qQiT_b6f9_2Ts',
          tag: 'VR展厅',
          type: '1',
          coverImgIdUrl: '1',
          coverImgId: '1'
          // showType: 'ZSXS_YWZTYS'
        },
        {
          mainTitle: '标题',
          subTitle: '副标题',
          Likes: '25436476666',
          publishTime: '2022/3/10',
          url: 'https://cscec.chineseworkers.com.cn/#/broadcast/detail?i=bde4b4ed-9524-4306-a412-716015f80237&viewType=exhibitionCenter',
          tag: '视频展播',
          type: '2',
          coverImgIdUrl: '1',
          coverImgId: '1'
        }
      ],
      this.Gridlist = [
        {
          id: 'da9f5c22-67f3-46b6-b7c7-3d69ea754256',
          courseName: '标题',
          courseIntroduce: '副标题',
          Likes: '1208574577',
          pageview: 210,
          courseImgUrl: defImg,
          learnNum: 11,
          bid: '1'
        },
        {
          id: '6baeac8b-8502-4b81-9d4b-de537c378ffc',
          courseName: '标题',
          courseIntroduce: '副标题',
          Likes: '1208574577',
          pageview: 111,
          courseImgUrl: defImg,
          learnNum: 18,
          bid: '1'
        },
        {
          id: 'f08e45c2-552b-48f7-ac4f-2340dd68089b',
          courseName: '标题',
          courseIntroduce: '副标题',
          Likes: '1208574577',
          pageview: 79,
          courseImgUrl: defImg,
          learnNum: 8,
          bid: '1'
        },
        {
          id: '0e821f88-60d3-4272-8077-8dc71f8a1141',
          courseName: '标题',
          courseIntroduce: '副标题',
          Likes: '1208574577',
          pageview: 58,
          courseImgUrl: defImg,
          learnNum: 15,
          bid: '1'
        }
      ]
      this.finished = false
      this.loading = false
      this.isLoading = false
    }
  },
  methods: {
    /**
     * 用于initData方法调用完设置数据
     */
    setData(result) {
      this.finished = false
      this.loading = false
      this.isLoading = false
      if (result !== 'error') {
        const { rows, total } = result?.dataList.data || {}
        this.list.push(...rows)
        this.setLabel(this.list, 'list')
        this.loading = false
        this.isLoading = false
        this.isNoData = total < 1
        if (this.isNoData) {
          this.finishedText = ''
        } else {
          this.finishedText = '已经到底了'
        }
        if (this.list.length >= total) {
          this.finished = true
        } else {
          this.finished = false
        }
      }
    },
    goPage(url) {
      return
      location.href = url
    },
    refresh4other() {
      return new Promise((resolve) => {
        this.finished = true
        this.page = 1
        this.list = []
        resolve()
      })
    },
    onRefresh() {
      if (!this.isInitData) {
        return
      }
      this.finished = false
      this.page = 1
      this.list = []
      this.getDataByCode('dataList')
    },

    onLoad() {
      if (!this.isInitData) {
        this.finished = false
        this.loading = false
        this.isLoading = false
        return
      }
      if (!this.isLoading) {
        this.page += 1
        this.getDataByCode('dataList')
      } else {
        this.loading = false
      }
    }
  }
}
</script>
<style lang="scss">
@import "@/styles/utility/rem.scss";

.exhibition-room-list-page {
  position: relative;

  .van-pull-refresh {

    ul {
      padding-top: rem(20);

      .list-item {
        margin-bottom: rem(20);
        position: relative;
        background-color: #fff;

        .news-list-style-one {
          border-radius: rem(12);
        }

        .news-list-style-three {
          border-radius: rem(12);
        }

        .news-list-style-six {
          border-radius: rem(12);
        }

        /*   overflow: hidden;
           background-color: #fff;
           display: flex;
           align-items: center;
           box-sizing: border-box;
           padding: rem(30);

           &:first-child {
             border-radius: rem(16) rem(16) 0 0;
           }
           &:last-child {
             border-radius: 0 0 rem(16) rem(16);
             &::after {
               height: 0;
             }
           }*/
        /*  &::after {
            content: "";
            height: 1px;
            background-color: #f1f1f1;
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
          }*/
      }
    }

    .box-item {
      width: rem(342);
      background: #ffffff;
      border-radius: rem(12);
      margin-bottom: rem(20);
      padding-bottom: rem(20);
      position: relative;

      .item-img {
        width: rem(342);
        height: rem(180);
        margin: 0 auto;
        position: relative;
        .van-image {
          width: 100%;
          height: 100%;
          border-radius: rem(12) rem(12) 0 0;
          overflow: hidden;
          .van-image__img {
            border-radius: rem(12) rem(12) 0 0;
          }

          .van-image__error {
            border-radius: rem(12) rem(12) 0 0;

            img {
              width: rem(120);
              height: rem(120);
            }
          }
        }
      }

      .item-bottom {
        margin-left: rem(15);
        position: relative;
        .item-title {
          line-height: 1.5;
          font-size: rem(30);
          font-weight: bold;
          text-align: left;
          color: #333333;
          margin-top: rem(15);
          // overflow: hidden;
          // text-overflow: ellipsis;
          // white-space: nowrap;
        }

        .item-desc {
          font-size: rem(24);
          font-weight: 400;
          text-align: left;
          color: #999999;
          margin-top: rem(15);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .item-number {
          font-size: rem(24);
          font-weight: 400;
          text-align: left;
          color: #999999;
          margin-top: rem(15);
        }
        .item-left-txt {
          font-size: rem(22);
          font-weight: 400;
          text-align: right;
          color: #999999;
          display: flex;
          align-items: center;
          justify-content: space-between;
          width: rem(40);
          position: absolute;
          right: rem(180);
          bottom: rem(-3);
        > span {
          display: inline-block;
          margin-right: rem(20);
        }
        > img {
          width: rem(49);
          height: rem(49);
          margin-bottom: rem(12);
        }
      }
      }
    }
    .list-box {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
    }
  }

}
</style>
